﻿// Original author contact info: Owen Emlen (owene_1998@yahoo.com)
// Note: other individuals may also have contributed to this code
// Project hosted on CodePlex.com as of 1/10/2009 at http://www.codeplex.com/EmlenMud
using System.Runtime.Serialization;
using System;
using System.Xml.Serialization;
using System.Threading;
using System.Reflection;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BrainTechLLC.ThreadSafeObjects;

namespace BrainTechLLC
{
    public class ChannelsCommand : Command, ICommandInfo
    {
        public override string HelpText { get { return "Manage communication channel settings"; } }

        [NonSerialized, XmlIgnore]
        public static List<string> Words = new List<string>() { "CHANNEL", "CHANNELS" };

        public override List<string> FirstWords { get { return Words; } }

        public static List<PerceivedEventAndAudience> PerformMethod(CommandToPerform cmd, IGameThing source, IGameThing target, PropertyData args, PropertyData modifyingArguments)
        {
            GameThingBaseClass sourceChar = source as GameThingBaseClass;
            List<PerceivedEventAndAudience> events = new List<PerceivedEventAndAudience>();

            var all = Everything.FindAllThingsOfType<Channel>();

            var list = all.BuildList((c) => c.ShortName + " - " + c.ShortDescription);

            EventToPerceive evt = CreateObservable(source, list);
            events.Add(new PerceivedEventAndAudience() { Event = evt, Audience = new AssociatedIDCollection(sourceChar.AssociatedID) });
                        
            return events;
        }

        public static EventToPerceive CreateObservable(IAssociatedID source, string text)
        {
            return new GeneralEventToPerceive()
            {                
                ShowToSource = new Event(text, ViewType.None),
                Sources = new AssociatedIDCollection(source.AssociatedID)
            };
        }

    }
}
